package com.by.controller;

import com.by.common.BaseResponse;
import com.by.model.entity.Blog;
import com.by.model.vo.BlogVO;
import com.by.service.BlogService;
import com.by.utils.ResultUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lzh
 */
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource
    private BlogService blogService;

    @GetMapping("/get")
    public BaseResponse<BlogVO> getBlogById(long id, HttpServletRequest request) {
        BlogVO blogVO = blogService.getBlogVoById(id, request);
        return ResultUtils.success(blogVO);
    }

    @GetMapping("/list")
    public BaseResponse<List<BlogVO>> listBlogVo(HttpServletRequest request) {
        List<Blog> blogList = blogService.list();
        List<BlogVO> blogVoList = blogService.getBlogVoList(blogList, request);
        return ResultUtils.success(blogVoList);
    }
}
